﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace SoftwareEngineering_Project
{
    public partial class Manage_Rooms : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                Room room = new Room();
                SqlDataReader myreader = room.getRooms("select * from room");
                Rooms.DataSource = myreader;
                Rooms.DataTextField = "Name";
                Rooms.DataValueField = "Room_ID";
                Rooms.DataBind();
                //GridView1.DataSource = room.getRooms("Select * from Room");
                //GridView1.DataBind();
                Video.Checked = room.hasVideo("select * from room where Room_ID ='" + Rooms.Text + "'");
                Phone.Checked = room.hasAudio("select * from room where Room_ID ='" + Rooms.Text + "'");
            }
        }

        protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Room room = new Room(RoomName.Text, NPhone.Checked, NVideo.Checked);
            room.AddtoDataBase();
            Errormessage.Visible = true;
            Errormessage.Text = "Room information were added successfully";
            Response.AddHeader("REFRESH", "2;URL=Manage Rooms.aspx");
        }

        protected void Rooms_SelectedIndexChanged(object sender, EventArgs e)
        {
            Room room = new Room();
            Video.Checked = room.hasVideo("select * from room where Room_ID ='" + Rooms.Text + "'");
            Phone.Checked = room.hasAudio("select * from room where Room_ID ='" + Rooms.Text + "'");


        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Room room = new Room();
            room.ExcuteNoresultsQuery("Delete from  Room Where Room_ID='" + Rooms.Text + "'");
            (new Logs()).CreateLog("12", "");
            Errormessage.Visible = true;
            Errormessage.Text = "Room information were deleted successfully";
            Response.AddHeader("REFRESH", "2;URL=Manage Rooms.aspx");
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Room room = new Room();
            room.ExcuteNoresultsQuery("Update Room SET Audio='" + Phone.Checked + "', Video='" + Video.Checked + "' where Room_ID='" + Rooms.Text + "'");
            (new Logs()).CreateLog("11", "");
            Errormessage.Visible = true;
            Errormessage.Text = "Room information were updated successfully";
            Response.AddHeader("REFRESH", "2;URL=Manage Rooms.aspx");
        }
    }
}